using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using Gencode.PrsCommon.App;

namespace Personalplaner
{
    [ToolboxItem(false)]
    public partial class OptionsDisplay : Gencode.Gengui.GUControl/* UserControl*/, IOptionsInterface
    {
        bool changed = false;

        Color saColor;
        Color soColor;
        Color numPlus;
        Color numEnough;
        Color numMinus;
        Color ferienColor;

        public OptionsDisplay()
        {
            InitializeComponent();
            setOptions();
        }

        public void save()
        {
            if (changed)
            {
                double check = 0;
                //SaveOptions saveOp = new SaveOptions();

                if (checkShowDay.Checked) { check = 1; } else { check = 0; }
                SaveOptions.SaveData("DisplayOptions", 1, check, "");

                if (checkShowPercent.Checked) { check = 1; } else { check = 0; }
                SaveOptions.SaveData("DisplayOptions", 2, check, "");

                if (checkShowColor.Checked) { check = 1; } else { check = 0; }
                SaveOptions.SaveData("DisplayOptions", 3, check, "");

                if (checkDienstHeader.Checked) { check = 1; } else { check = 0; }
                SaveOptions.SaveData("DienstGrid", 1, check, "");

                //Samstag Farben
                SaveOptions.SaveData("GridColor", 1, saColor.ToArgb(), saColor.Name);
                //Sontag Farben
                SaveOptions.SaveData("GridColor", 2, soColor.ToArgb(), soColor.Name);
                //Ferien Farben
                SaveOptions.SaveData("GridColor", 3, ferienColor.ToArgb(), ferienColor.Name);
                //dienste plus
                SaveOptions.SaveData("DienstGridColor", 1, numPlus.ToArgb(), numPlus.Name);
                //genug dienste
                SaveOptions.SaveData("DienstGridColor", 2, numEnough.ToArgb(), numEnough.Name);
                //minus dienste
                SaveOptions.SaveData("DienstGridColor", 3, numMinus.ToArgb(), numMinus.Name);

                changed = false;
            }
        }

        private void setOptions()
        {
            bool check = false;
			if ((int)Option.NumberValue("DisplayOptions", 1) == 1) { check = true; } else { check = false; }
            checkShowDay.Checked = check;

			if ((int)Option.NumberValue("DisplayOptions", 2) == 1) { check = true; } else { check = false; }
            checkShowPercent.Checked = check;

			if ((int)Option.NumberValue("DisplayOptions", 3) == 1) { check = true; } else { check = false; }
            checkShowColor.Checked = check;

			if ((int)Option.NumberValue("DienstGrid", 1) == 1) { check = true; } else { check = false; }
            checkDienstHeader.Checked = check;

			saColor = Color.FromName(Option.StringValue("GridColor", 1));
			saColor = Color.FromArgb((int)Option.NumberValue("GridColor", 1));
            try
            {
                txtSa.BackColor = saColor;
            }
            catch { }

			soColor = Color.FromName(Option.StringValue("GridColor", 2));
			soColor = Color.FromArgb((int)Option.NumberValue("GridColor", 2));
            try
            {
                txtSo.BackColor = soColor;
            }
            catch { }

			ferienColor = Color.FromName(Option.StringValue("GridColor", 3));
			ferienColor = Color.FromArgb((int)Option.NumberValue("GridColor", 3));
            try
            {
                txtFerien.BackColor = ferienColor;
            }
            catch { }

			numPlus = Color.FromName(Option.StringValue("DienstGridColor", 1));
			numPlus = Color.FromArgb((int)Option.NumberValue("DienstGridColor", 1));
            try
            {
                txtNumPus.BackColor = numPlus;
            }
            catch { }

			numEnough = Color.FromName(Option.StringValue("DienstGridColor", 2));
			numEnough = Color.FromArgb((int)Option.NumberValue("DienstGridColor", 2));
            try
            {
                txtNumEnough.BackColor = numEnough;
            }
            catch { }

			numMinus = Color.FromName(Option.StringValue("DienstGridColor", 3));
			numMinus = Color.FromArgb((int)Option.NumberValue("DienstGridColor", 3));
            try
            {
                txtNumMinus.BackColor = numMinus;
            }
            catch { }

            changed = false;
        }

        private Color getColorDialog()
        {
            string colourName = "";
            int argb = 0;

            ColorDialog color = new ColorDialog();
            if (color.ShowDialog() == DialogResult.OK)
            {
                colourName = color.Color.Name;
                argb = color.Color.ToArgb();
                changed = true;
            }

            Color col = Color.FromName(colourName);
            col = Color.FromArgb(argb);

            return col;
        }

        public bool checkIfChanged()
        {
            return changed;
        }

        private void checkShowDay_CheckedChanged(object sender, EventArgs e)
        {
            changed = true;
        }

        private void checkShowPercent_CheckedChanged(object sender, EventArgs e)
        {
            changed = true;
        }

        private void checkShowColor_CheckedChanged(object sender, EventArgs e)
        {
            changed = true;
        }

        private void btnColSa_Click(object sender, EventArgs e)
        {
            saColor = getColorDialog();
            try
            {
                txtSa.BackColor = saColor;
            }
            catch { }
        }

        private void btnColSo_Click(object sender, EventArgs e)
        {
            soColor = getColorDialog();
            try
            {
                txtSo.BackColor = soColor;
            }
            catch { }
        }

        private void btnNumPlus_Click(object sender, EventArgs e)
        {
            numPlus = getColorDialog();
            try
            {
                txtNumPus.BackColor = numPlus;
            }
            catch { }
        }

        private void btnNumEnough_Click(object sender, EventArgs e)
        {
            numEnough = getColorDialog();
            try
            {
                txtNumEnough.BackColor = numEnough;
            }
            catch { }
        }

        private void btnNumMinus_Click(object sender, EventArgs e)
        {
            numMinus = getColorDialog();
            try
            {
                txtNumMinus.BackColor = numMinus;
            }
            catch { }
        }

        private void btnFerien_Click(object sender, EventArgs e)
        {
            ferienColor = getColorDialog();
            try
            {
                txtFerien.BackColor = ferienColor;
            }
            catch { }
        }
    }
}
